﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ArduinoSharp.Lib;

namespace ArduinoControllApp_WF
{
    public class KeyHandler
    {
        ArduinoCommand command = new ArduinoCommand();
        SerialPort serialPort;

        private Dictionary<Key, Action<bool>> keyConfig = new Dictionary<Key,Action<bool>>();

        //public KeyHandler(SerialPort serial)
        //{
        //    this.serialPort = serial;
        //}
        public KeyHandler()
        {
            this.command = new ArduinoCommand();
            this.SetDefaultConfig();
        }

        public void SetDefaultConfig()
        {
            keyConfig.Clear();
            keyConfig.Add(Key.W, x => this.command.MoveFoward = x);
            keyConfig.Add(Key.S, x => this.command.MoveBackwar = x);
            keyConfig.Add(Key.A, x => this.command.RotateLeft = x);
            keyConfig.Add(Key.D, x => this.command.RotateRight = x);
        }

        public void ImportConfig()
        {
            throw new NotImplementedException();
        }

        public void ExportConfig()
        {
            throw new NotImplementedException();
        }

        public string Process()
        {
            foreach (var conf in keyConfig)
            {
                conf.Value(Keyboard.IsKeyDown(conf.Key));
            }
            //this.serialPort.Write(command.GetComandStr());
            return command.GetComandStr();
        }


    }

}
